package com.linkhub.oms.admin.modules.user.accountflow.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.linkhub.oms.admin.modules.satoken.session.LhSessionContext;
import com.linkhub.oms.admin.modules.user.accountflow.domain.param.UserAccountFlowQueryParam;
import com.linkhub.oms.admin.modules.user.accountflow.domain.vo.FreightAccountFlowDetailVO;
import com.linkhub.oms.admin.modules.user.accountflow.domain.vo.PickUpAccountFlowDetailVO;
import com.linkhub.oms.admin.modules.user.accountflow.domain.vo.ProcessingAccountFlowDetailVo;
import com.linkhub.oms.admin.modules.user.accountflow.domain.vo.UserAccountFlowSimpleVO;
import com.linkhub.oms.admin.modules.user.accountflow.domain.vo.UserAccountFlowVO;
import com.linkhub.oms.admin.modules.user.accountflow.service.IUserAccountFlowBizService;
import com.linkhub.oms.admin.modules.user.accountflow.service.IUserAccountFlowDetailService;
import com.linkhub.oms.admin.modules.user.domain.param.BasePageParam;
import com.linkhub.oms.common.constant.RoleConstant;
import com.linkhub.oms.common.response.DataResponse;
import com.linkhub.oms.common.response.PageDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 用户账户_资金流水模块
 *
 * @author Frank
 */
@Slf4j
@RestController
@Api(tags = {"用户账户_资金流水模块接口"})
@RequestMapping("/user/account/flow")
@SaCheckLogin
public class UserAccountFlowController {
    @Resource
    private IUserAccountFlowBizService userAccountFlowService;

    @Resource
    private IUserAccountFlowDetailService userAccountFlowDetailService;

    @GetMapping()
    @ApiOperation(value = "资金流水列表")
    @SaCheckRole(value = {RoleConstant.CUSTOMER, RoleConstant.EMPLOYEE}, mode = SaMode.OR)
    public DataResponse<PageDTO<UserAccountFlowVO>> getAccountFlowPage(@Validated UserAccountFlowQueryParam userAccountFlowQueryParam) {
        userAccountFlowQueryParam.setUserId(LhSessionContext.getUserId());
        userAccountFlowQueryParam.setCustomRoleFlag(LhSessionContext.isCustomerRole());
        return DataResponse.success(userAccountFlowService.getAccountFlowPage(userAccountFlowQueryParam));
    }

    @GetMapping("/freeze")
    @ApiOperation(value = "冻结金额列表")
    @SaCheckRole(value = {RoleConstant.CUSTOMER})
    public DataResponse<PageDTO<UserAccountFlowSimpleVO>> getFreezeFlowPage(@Validated BasePageParam pageParam) {
        pageParam.setUserId(LhSessionContext.getUserId());
        pageParam.setCustomRoleFlag(LhSessionContext.isCustomerRole());
        return DataResponse.success(userAccountFlowService.getFreezeFlowPage(pageParam));
    }

    @GetMapping("/detail/freight/{transactionId}")
    @ApiOperation(value = "运费资金流水明细")
    @SaCheckRole(value = {RoleConstant.CUSTOMER, RoleConstant.EMPLOYEE}, mode = SaMode.OR)
    public DataResponse<FreightAccountFlowDetailVO> queryFreightAccountFlowDetail(@PathVariable String transactionId) {
        return DataResponse.success(userAccountFlowDetailService.queryFreightAccountFlowDetail(transactionId));
    }

    @GetMapping("/detail/processing/{transactionId}")
    @ApiOperation(value = "加工费资金流水明细")
    @SaCheckRole(value = {RoleConstant.CUSTOMER, RoleConstant.EMPLOYEE}, mode = SaMode.OR)
    public DataResponse<ProcessingAccountFlowDetailVo> queryProcessingAccountFlowDetail(@PathVariable String transactionId) {
        return DataResponse.success(userAccountFlowDetailService.queryProcessingAccountFlowDetail(transactionId));
    }

    @GetMapping("/detail/pickUpOrder/{transactionId}")
    @ApiOperation(value = "提货费资金流水明细")
    @SaCheckRole(value = {RoleConstant.CUSTOMER, RoleConstant.EMPLOYEE}, mode = SaMode.OR)
    public DataResponse<PickUpAccountFlowDetailVO> queryPickUpAccountFlowDetail(@PathVariable String transactionId) {
        return DataResponse.success(userAccountFlowDetailService.queryPickUpAccountFlowDetail(transactionId));
    }

}
